//
// Created by Semir on 2020/4/2.
//

#include <iostream>

using namespace std;

const int MAX_N = 30010;
const int MAX_M = 35;
int n, m;
int money[MAX_M];
int importance[MAX_M];
int dp[MAX_N] = {0};

void plan() {
    for (int i = 1; i <= m; i++) {
        for (int j = n; j >= money[i]; j--) {
            dp[j] = max(dp[j - money[i]] + importance[i] * money[i], dp[j]);
        }
    }
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> money[i] >> importance[i];
    }
    plan();
    cout << dp[n] << endl;
    return 0;
}
